from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import unittest,time,logging
from Tools import Tools
Tools()
class Case(unittest.TestCase):
    def setUp(self):
        self.driver=webdriver.Edge()
        self.driver.get('http://10.59.9.14:7003/')
        time.sleep(2)
    def tearDown(self):
        time.sleep(3)
        self.driver.quit()
    def test_a3mall_login(self):
        logging.info("用例1：通过")
        # 点击请登录
        self.driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
        # 输入框输入用户名和密码
        self.driver.find_element(By.NAME,'username').send_keys('13811033962')
        self.driver.find_element(By.NAME,'password').send_keys('123456')
        time.sleep(5)
        # 点击登录按钮
        self.driver.find_element(By.XPATH,'//*[@id="theForm"]/div[5]/a').click()
        time.sleep(2)
    def test_a3mall_buy(self):
        logging.info("用例2：通过")
        self.test_a3mall_login()
        # 点击首页
        self.driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a').click()
        # 输入框搜索并回车
        self.driver.find_element(By.XPATH,'//*[@id="searchForm"]/div[1]/input').send_keys("手机")
        time.sleep(2)
        self.driver.find_element(By.XPATH,'//*[@id="searchForm"]/div[1]/input').send_keys(Keys.ENTER)
        time.sleep(2)
        # 点击商品
        self.driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li[1]/div[1]/span/a/img').click()
        time.sleep(2)
        # 点击立即购买
        self.driver.find_element(By.XPATH,'//*[@id="buy-cart"]').click()
        time.sleep(2)
        # 点击下一步
        self.driver.find_element(By.XPATH,'//*[@id="order-button"]').click()
        time.sleep(3)
        # 点击查看订单
        self.driver.find_element(By.XPATH,'/html/body/div[4]/div[3]/p/a')
        time.sleep(3)
if __name__ == '__main__':
    unittest.main()
